Command Line Basics
University of South Florida
pwd: Print working directory addressls: List directory contentscd: Change directorymkdir: Make (create) a new directory. (dot):
cd . keeps you in the current directory, explicitly specifying the current directory... (double dot):
cd .. moves you up one directory level.~ (tilde):
cd ~ navigates to the home directory./ (slash):
C:\cd / navigates to the root directory.- (hyphen):
cd - navigates to the previous directory.cd ../folder).cd /home/user/folder).pwd to display your current working directory...). Print the working directory.~ and display the address.FIN4770), wherever you’d like to.~/FIN4770 should be the addressIn your classroom folder, create a temporary file named temp, verify it exists (ls), then remove it.
Create a temporary directory named tempdir, verify it exists.
Create a temporary file temp2 inside tempdir.
Try to remove the folder temdir with rmdir. What happens?
Remove the temporary directory properly.
~.FIN4770 folder. Use (-).test.sh then rename it to example.sh.shell.example.sh into the shell subdirectory.example.sh you just created.echo and PipesechoBasic usage:
Redirecting output to a new file:
Appending output to an (existing) file:
Using echo with wc:
echo to display the text Learning Shell is fun.echo "Learning Shell is fun" to a file named Shell_fun.txt.echo and wc to:
Shell pipes are powerful.Two common command-line text editors:
nano: Beginner-friendly, simple interface
vim: For Pros, Nerds … like me
nanoCtrl + O: Save fileCtrl + X: Exit editorCtrl + K: Cut (remove) linevimh, j, k, l: Move left, down, up, righti: Insert mode (to edit text)Esc: Command mode:q: Quit:q!: Quit without saving:w: Write file:wq: Write and quitYou can create alias that can be used easily. For example, if I wanted to alias my class folder:
After restarting terminal typing f4770 will change directory.
Open a text file with nano. Write “Hello world!” and save it as nano_text.txt in shell folder.
Generate a text with vim, write some text, and save as vim_text.txt in shell folder.
(Homework) Generate alias for your class directory. Write text file with exact file location and name:
~/.bashrc (windows) or ~/.zshrc (mac).For those who are devoted…
vimtutor: teaches you how to use vim in the command line.
vimHero: Great interactive tutorial for vim
vim Adventure: Game that teaches you how to use vim.
Downloading Data on current directory
curl (general tool):wget (specifically for downloads):curl or wgetNavigate to your FIN4770 folder, make a subfolder Data then navigate to it.
Download a sample dataset using either wget or curl.
Note
In case of certification error, try:
curl –ssl-no-revoke -O https://…/iris.csv
ls -l Output-rw-r--r--: File type and permissions:
-: Regular filed: Directoryl: Symbolic link (symlink)-rw-r--r--: File type and permissions:
rw-)r--)r--)r: Read permissionw: Write permissionx: Execute permission-: No permissionrw-: Read and write, but no executer--: Read-onlyrwx: Read, write, and execute1: Number of hard links to the file or directory.
user: The owner of the file.
group: The group associated with the file.
1234: The size of the file in bytes.
Jan 25 10:30: The last modification date and time.
example.txt: The name of the file or directory.
Output:
drwxr-xr-x 2 user group 4096 Jan 25 12:00 folder
-rw-r--r-- 1 user group 1234 Jan 25 10:30 file.txt
lrwxrwxrwx 1 user group 20 Jan 25 10:45 link -> /path/to/target
Explanation of drwxr-xr-x for folder:
Check the permissions of iris file you downloaded.
r): 4w): 2x): 1-): 0756 breaks down as:
rwx (4 + 2 + 1 = 7)r-x (4 + 0 + 1 = 5)rw- (4 + 2 + 0 = 6)ls -l.rwxr---w- using chmod.chmod 600 file.txt.Use a text editor like nano or vim to create a script file:
Begin with a shebang to specify the shell interpreter:
Add commands to the script:
Ctrl + O and Ctrl + X in nano).Grant execute permissions to the script using chmod:
Execute the script by specifying its path:
Run the script without changing permissions by invoking the shell directly:
Create a script file named greet.sh that:
Add execute permissions.
Run the script.
ps u to display your running processes.sleep 5. What does it do?sleep 100 & and view it with ps u or jobs.kill <PID>.View command history:
Repeat a command:
Run a specific command from history:
Clear the command history:
!! to repeat the last command.!<number> to execute a specific command from the history list.Ctrl + r and type keyword to find a previously used command.history.Ctrl + A: Move to the beginning of the lineCtrl + E: Move to the end of the lineCtrl + U: Delete everything before the cursorCtrl + K: Delete everything after the cursorCtrl + W: Delete the word before the cursorCtrl + R: Search your command history interactively
Ctrl + R repeatedly to cycle through matchesCtrl + L: Clear the terminal screen (history preserved)clear: Clear and remove historyFIN4770: Programming for FinTech